package com.crecheng.shop.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.crecheng.shop.Manage.ItemKindManage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ItemKindController {
    @RequestMapping("/ItemKind/get")
    public @ResponseBody
    String getItemKind(@RequestParam(value = "id",defaultValue = "-1")int id,
                       @RequestParam(value = "parent",defaultValue = "-1")int parent){
        if(parent==-1) {
            if (id == -1)
                return JSONArray.toJSONString(ItemKindManage.getAll());
            else
                return JSON.toJSONString(ItemKindManage.get(id));
        }
        else {
            return JSONArray.toJSONString(ItemKindManage.getByParent(parent));
        }
    }
}
